home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / vb / tree_rs.exe / TREE.FRM < prev   
Encoding:
Text File  |  1993-02-06  |  4.9 KB  |  178 lines

  1. Version 1.00
  2. BEGIN Form Tree
  3.     AutoRedraw   = 0
  4.     BackColor    = QBColor(7)
  5.     BorderStyle  = 2
  6.     Caption      = "Tree"
  7.     ControlBox   = -1
  8.     Enabled      = -1
  9.     ForeColor    = QBColor(0)
  10.     Height       = Char(19)
  11.     Left         = Char(8)
  12.     MaxButton    = -1
  13.     MinButton    = -1
  14.     MousePointer = 0
  15.     Tag          = ""
  16.     Top          = Char(2)
  17.     Visible      = -1
  18.     Width        = Char(64)
  19.     WindowState  = 0
  20.     BEGIN ListBox Liste1
  21.         BackColor    = QBColor(7)
  22.         DragMode     = 0
  23.         Enabled      = -1
  24.         ForeColor    = QBColor(0)
  25.         Height       = Char(13)
  26.         Left         = Char(2)
  27.         MousePointer = 0
  28.         Sorted       = 0
  29.         TabIndex     = 0
  30.         TabStop      = -1
  31.         Tag          = ""
  32.         Top          = Char(1)
  33.         Visible      = -1
  34.         Width        = Char(58)
  35.     END
  36.     BEGIN CommandButton Befehl1
  37.         BackColor    = QBColor(7)
  38.         Cancel       = 0
  39.         Caption      = "Exit"
  40.         Default      = 0
  41.         DragMode     = 0
  42.         Enabled      = -1
  43.         Height       = Char(3)
  44.         Left         = Char(2)
  45.         MousePointer = 0
  46.         TabIndex     = 1
  47.         TabStop      = -1
  48.         Tag          = ""
  49.         Top          = Char(14)
  50.         Visible      = -1
  51.         Width        = Char(12)
  52.     END
  53. END
  54. DEFINT A-Z
  55.  
  56. ' This is a simple form to show how I handled the
  57. ' display of a tree with dynamic expanding and
  58. ' compressing.
  59. '
  60. ' I used it in a program to display structured data
  61. ' from a Netware SQL database which was too big to
  62. ' use a control like MicroHelp's MhTree.
  63. '
  64. ' This is only a small extract of the code for the
  65. ' form where some features are added like showing
  66. ' a plus (+) character in a line that can be
  67. ' extracted and so on.
  68. '
  69. ' If anyone out there uses and enhances my routines
  70. ' please let me know.
  71. ' I can be reached at Compuserve ID 100021,2304
  72. '
  73. ' Ralf Stoepper
  74.  
  75. SUB Befehl1_Click ()
  76. END
  77. END SUB
  78.  
  79. SUB Form_Load ()
  80. tree.liste1.ADDITEM "Root"       ' initialize listbox
  81. tree.SHOW
  82. tree.liste1.SETFOCUS
  83. END SUB
  84.  
  85. SUB Liste1_DblClick ()
  86. index = liste1.listindex
  87.  
  88. ' Calculate beginning position of text (begpos)
  89.  
  90. s$ = liste1.list(index)
  91. begpos = INSTR(s$, "└")
  92. IF begpos < 1 THEN
  93.     begpos = INSTR(s$, "├")
  94. END IF
  95.  
  96. ' look at folowing item to see if expand or compress
  97.  
  98. s$ = liste1.list(index + 1)
  99. pp = INSTR(begpos + 1, s$, "└")
  100. IF pp < 1 THEN
  101.     pp = INSTR(begpos + 1, s$, "├")
  102. END IF
  103. IF pp > 0 THEN
  104.     ' compress
  105.     l = index + 1                       ' next index
  106.     DO
  107.         s$ = liste1.list(l)
  108.  
  109.         pp = INSTR(begpos + 1, s$, "└")      ' calculate depth
  110.         IF pp < 1 THEN
  111.             pp = INSTR(begpos + 1, s$, "├")
  112.         END IF
  113.  
  114.         IF pp > 0 THEN                  ' if current item deeper than startitem
  115.             liste1.REMOVEITEM l         ' remove it
  116.         END IF
  117.  
  118.         IF liste1.listcount <= l THEN   ' if current item = last item then stop
  119.             pp = 0
  120.         END IF
  121.     LOOP UNTIL pp < 1
  122. ELSE
  123.     ' expand
  124.     IF begpos = 0 THEN                  ' If first then
  125.         start = 0                       ' start at first column
  126.     ELSE                                ' else
  127.         start = begpos + 3              ' startcolumn is 3 columns deeper
  128.     END IF
  129.  
  130.     vor$ = SPACE$(start)                ' build headerstring
  131.  
  132.     s$ = liste1.list(index)             ' look at selected string to
  133.     i = 0                               ' see where to put in "│"
  134.     DO
  135.         i = INSTR(i + 1, s$, "│")       ' if original string contains "│"
  136.         IF i > 0 AND i <= begpos THEN
  137.             MID$(vor$, i, 1) = "│"      ' then put "│" in header
  138.         END IF
  139.     LOOP WHILE i > 0
  140.     i = 0
  141.     DO
  142.         i = INSTR(i + 1, s$, "├")       ' if original string contains "│"
  143.         IF i > 0 AND i <= begpos THEN
  144.             MID$(vor$, i, 1) = "│"      ' then put "│" in header
  145.         END IF
  146.     LOOP WHILE i > 0
  147.  
  148.     l = liste1.listindex + 1            ' Index where to add item
  149.  
  150.     ' getfirst                         
  151.     aus$ = " 1"                         'this should be replaced by a routine
  152.                                         'to calculate the first sub-item
  153.                                         'The routine should return a zero string ("")
  154.                                         'when no sub-item is found
  155.  
  156.  
  157.     WHILE aus$ <> ""
  158.         pfeil$ = "├──"
  159.         liste1.ADDITEM vor$ + pfeil$ + aus$, l
  160.  
  161.         ' get next                      'this should be replaced by a routine
  162.         IF VAL(aus$) = 3 THEN           'to calculate the next sub-item
  163.             aus$ = ""                   'The routine should return a zero string ("")
  164.         ELSE                            'when no sub-item is found
  165.             aus$ = STR$(VAL(aus$) + 1)
  166.         END IF
  167.  
  168.         l = l + 1                           ' next index to add item
  169.         IF aus$ = "" THEN                   ' if no next item can be found then
  170.             s$ = liste1.list(l - 1)         ' place a "└".
  171.             MID$(s$, start + 1, 1) = "└"
  172.             liste1.list(l - 1) = s$
  173.         END IF
  174.     WEND
  175. END IF
  176. END SUB
  177.  
  178.